<%@page import="com.grom.service.GcmsUserService"%>
<%@page import="com.grom.service.CustomerService"%>
<%@page import="com.grom.util.SecurityUtil"%>
<%@page import="com.grom.po.GcmsUser"%>
<%@page import="com.grom.po.Customer"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/js/themes/icon.css">
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-1.6.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery.easyui.min.js"></script>
<script type="text/javascript">
$(function(){
	$('#loginInfoEdit_cus').dialog({  
	    title : 'Customer Info',  
	    modal: true,  
	    collapsible : true,    
	    resizable : true   
	});  
	$('#loginInfoEdit_cus').dialog('close');
	$('#loginInfoEdit_brand').dialog({  
	    title : 'brand Info',  
	    modal: true,  
	    collapsible : true,    
	    resizable : true   
	});  
	$('#loginInfoEdit_brand').dialog('close');
	$('#loginInfoEdit_store').dialog({  
	    title : 'store ',  
	    modal: true,  
	    collapsible : true,    
	    resizable : true   
	});  
	$('#loginInfoEdit_store').dialog('close');
});

function clearTheContactInfoAndHistory(){
	$('#contactInfo').val("");
	$('#contactInfoDiv').html("");
	$('#hisToryInfoDiv').html("");
}

function viewCusDetail(cusId){
	$.ajax({
	    url: '<%=request.getContextPath()%>/CustomerAction/getDetail.do?itemid='+cusId,
	    type: 'GET',
	    timeout: 1000,
	    error: function(){
	        alert('Error getting response!');
	    },
	    success: function(json){
	        var customer = eval(json);
	        $('#cusType').val(customer.cusType);
	        $('#brandName').val(customer.brandName);
	        $('#visitedAddress').val(customer.visitedAddress);
	        $('#customerName').val(customer.customerName);
	        $('#averageSale').val(customer.averageSale);
	        $('#storeNum').val(customer.storeNum);
	        $('#monthlyCoverNum').val(customer.monthlyCoverNum);
	        $('#monthlyCoverDay').val(customer.monthlyCoverDay);
	        $('#cusFlowCover').val(customer.cusFlowCover);
	        $('#cusFlowCoverWay').val(customer.cusFlowCoverWay);
	        $('#distanceStoreCover').val(customer.distanceStoreCover);
	        $('#distanceStoreCoverWay').val(customer.distanceStoreCoverWay);
	        $('#everUsedFlowCover').val(customer.everUsedFlowCover);
	        $('#everUsedDistanceStoreCover').val(customer.everUsedDistanceStoreCover);
	        $('#reasonOfNotUsed').val(customer.reasonOfNotUsed);
	        $('#wantUse').val(customer.wantUse);
	        $('#reasonOfRefuse').val(customer.reasonOfRefuse);
	        $('#importantFunction').val(customer.importantFunction);
	        $('#chargeWayWanted').val(customer.chargeWayWanted);
	        $('#cusFlowChargeWanted').val(customer.cusFlowChargeWanted);
	        $('#storeCoverChargeWanted').val(customer.storeCoverChargeWanted);
	        $('#userId').val(customer.userId);
	        $('#webSite').val(customer.webSite);
	        $('#flowCoverType').val(customer.flowCoverType);
	        $('#inforSource').val(customer.inforSource);
	        clearTheContactInfoAndHistory();
	        for(var i = 0 ; i < customer.contactInfo.length ; i++){
	        	var html="";
	        	html += customer.contactInfo[i].contactPerson + "-" + customer.contactInfo[i].contactPhone;
	        	if($('#contactInfo').val()==""){
					$('#contactInfoDiv').html("<span id='"+html+"'>"+html+"&nbsp;</span>");
					$('#contactInfo').val(html);
				}else{
					$('#contactInfoDiv').append("<br><span id='"+html+"'>"+html+"&nbsp;</span>");
					$('#contactInfo').val($('#contactInfo').val()+","+ html);
				}
	        }
	        disableAll();
			$('#loginInfoEdit_cus').dialog('open');
	    }
	});
}
function viewBrandDetail(brandId){
	$.ajax({
	    url: '<%=request.getContextPath()%>/BrandAction/getDetail.do?itemid='+brandId,
	    type: 'GET',
	    timeout: 1000,
	    error: function(){
	        alert('Error getting response!');
	    },
	    success: function(json){
	        var brand = eval(json);
	        $('#ppId_b').val(brand.ppId);
	        $('#brandCode_b').val(brand.brandCode);
	        $('#brandName_b').val(brand.brandName);
	        $('#companyName_b').val(brand.companyName);
	        $('#webSite_b').val(brand.webSite);
	        $('#clothType_b').val(brand.clothType);
	        $('#dealScope_b').val(brand.dealScope);
	        $('#dealArea_b').val(brand.dealArea);
	        $('#storeNum_b').val(brand.storeNum);
	        $('#chargeScope_b').val(brand.chargeScope);
	        $('#averageSale_b').val(brand.averageSale);
	        $('#storeAcreage_b').val(brand.storeAcreage);
	        $('#bestSale_b').val(brand.bestSale);
	        $('#wayOfSale_b').val(brand.wayOfSale);
	        $('#everUseABD_b').val(brand.everUseABD);
	        $('#nameOfABD_b').val(brand.nameOfABD);
	        $('#Address_b').val(brand.Address);
	        $('#Phone_b').val(brand.Phone);
	        $('#Email_b').val(brand.Email);
	        $('#faxNum_b').val(brand.faxNum);
	        $('#mainManager_b').val(brand.mainManager);
	        $('#contactToMain_b').val(brand.contactToMain);
	        $('#contactToABD_b').val(brand.contactToABD);
	        $('#userId_b').val(brand.userId);
	        $('#customerId_b').val(brand.customerId);
	        $('#chargerType_b').val(brand.chargerType);
	        clearTheContactInfoAndHistory();
	        for(var i = 0 ; i < brand.contactInfo.length ; i++){
	        	var html="";
	        	html += brand.contactInfo[i].contactPerson + "-" + brand.contactInfo[i].contactPhone;
	        	if($('#contactInfo').val()==""){
					$('#contactInfoDiv_b').html("<span id='"+html+"'>"+html+"&nbsp;<a href='#' onclick=\"removeFromContact('"+html+"')\">remove</a></span>");
					$('#contactInfo').val(html);
				}else{
					$('#contactInfoDiv_b').append("<br><span id='"+html+"'>"+html+"&nbsp;<a href='#' onclick=\"removeFromContact('"+html+"')\">remove</a></span>");
					$('#contactInfo').val($('#contactInfo').val()+","+ html);
				}
	        }
	        for(var i=0 ; i < brand.historys.length; i++){
	        	$('#historyInfo').val($('#historyInfo').val()+"-"+brand.historys[i].detailInfo);
		        $('#hisToryInfoDiv').append("<p>"+brand.historys[i].detailInfo+"</p>");
	        }
	        disableAll();
			$('#loginInfoEdit_brand').dialog('open');
	    }
	});
}

function viewStoreDetail(itemId){
	$.ajax({
	    url: '<%=request.getContextPath()%>/StoreAction/getDetail.do?itemid='+itemId,
	    type: 'GET',
	    timeout: 1000,
	    error: function(){
	        alert('Error getting response!');
	    },
	    success: function(json){
	        var store = eval(json);
	        $('#shopID_s').val(store.shopID);
	        $('#codeOfABDCode_s').val(store.codeOfABDCode);
	        $('#managerOfABD_s').val(store.managerOfABD);
	        $('#phoneOfABDManager_s').val(store.phoneOfABDManager);
	        $('#countSystem_s').val(store.countSystem);
	        $('#chargeSystem_s').val(store.chargeSystem);
	        $('#storeCoverSystem_s').val(store.storeCoverSystem);
	        $('#storeAddress_s').val(store.storeAddress);
	        $('#storeManeger_s').val(store.storeManeger);
	        $('#phoneOfStoreManager_s').val(store.phoneOfStoreManager);
	        $('#urgentStoreContactor_s').val(store.urgentStoreContactor);
	        $('#urgentStoreContactPhone_s').val(store.urgentStoreContactPhone);
	        $('#projectManager_s').val(store.projectManager);
	        $('#phoneOfProjectManager_s').val(store.phoneOfProjectManager);
	        $('#broadBandAccount_s').val(store.broadBandAccount);
	        $('#broadBandPassword_s').val(store.broadBandPassword);
	        $('#areaOfStore_s').val(store.areaOfStore);
	        $('#bestSaleOfStore_s').val(store.bestSaleOfStore);
	        $('#clothType_s').val(store.clothType);
	        $('#chargeScope_s').val(store.chargeScope);
	        $('#dealScope_s').val(store.dealScope);
	        $('#dealArea_s').val(store.dealArea);
	        $('#operatePermission_s').val(store.operatePermission);
	        $('#operateTime_s').val(store.operateTime);
	        $('#independencyElectric_s').val(store.independencyElectric);
	        $('#broadBandAmount_s').val(store.broadBandAmount);
	        $('#faxNum_s').val(store.faxNum);
	        $('#Addresss_s').val(store.Addresss);
	        $('#Phone_s').val(store.Phone);
	        $('#Email_s').val(store.Email);
	        $('#brandName_s').val(store.brandName);
	        $('#webSite_s').val(store.webSite);
	        $('#isABDUser_s').val(store.isABDUser);
	        $('#isInRequisition_s').val(store.isInRequisition);
	        $('#chunnelMaterial_s').val(store.chunnelMaterial);
	        $('#heightOfChunnel_s').val(store.heightOfChunnel);
	        $('#numOfChunnel_s').val(store.numOfChunnel);
	        $('#monthlyAverageSale_s').val(store.monthlyAverageSale);
	        $('#userId_s').val(store.userId);
	        $('#customerId_s').val(store.customerId);
	        disableAll();
			$('#loginInfoEdit_store').dialog('open');
	    }
	});
}


function doSearch(){
	$('#searchForm').submit();
}

function listBrand(cusId){
	$.ajax({
	    url: '<%=request.getContextPath()%>/QueryAction/getAllBrand.do?itemid='+cusId,
	    type: 'GET',
	    timeout: 1000,
	    error: function(){
	        alert('Error getting response!');
	    },
	    success: function(json){
	        var brands = eval(json);
	        $('#detail_'+cusId).html("");
	        if(brands.length==0){
	        	$('#detail_'+cusId).html("no data for brands!");
	        }
	        $.each(brands,function(idx,item){
	        	$('#detail_'+cusId).append("<a href=\"#\" onclick=\"viewBrandDetail('"+item.ID+"')\">"+item.brandName+"</a> ");;
	        });
	    }
	});
}
function listStore(cusId){
	$.ajax({
	    url: '<%=request.getContextPath()%>/QueryAction/getAllStore.do?itemid='+cusId,
	    type: 'GET',
	    timeout: 1000,
	    error: function(){
	        alert('Error getting response!');
	    },
	    success: function(json){
	        var stores = eval(json);
	        $('#detail_'+cusId).html("");
	        if(stores.length==0){
	        	$('#detail_'+cusId).html("no data for store!");
	        }
	        $.each(stores,function(idx,item){
	        	$('#detail_'+cusId).append("<a href=\"#\" onclick=\"viewStoreDetail('"+item.ID+"')\">"+item.storeAddress+"</a> ");;
	        });
	    }
	});
}

function disableAll(){
	$('#userId').attr("disabled","disabled");
	$('#customerId').attr("disabled","disabled");
	$('#userId_b').attr("disabled","disabled");
	$('#customerId_b').attr("disabled","disabled");
	$('#userId_store').attr("disabled","disabled");
	$('#customerId_s').attr("disabled","disabled");
}

function exportCusInfo(){
	window.open("<%=request.getContextPath() %>/ExportAction/exportAllCustomer.do");
}

function exportBrandInfo(){
	window.open("<%=request.getContextPath() %>/ExportAction/exportAllBrand.do");
}

function exportStoreInfo(){
	window.open("<%=request.getContextPath() %>/ExportAction/exportAllStore.do");
}
</script>
<title>查询页面</title>
</head>
<body>
<div style="font-size: 10px;">
<form id="searchForm" name="searchForm" action="<%=request.getContextPath() %>/QueryAction/doQuery.do" method="post">
      <label>客户分类：</label>  
      <select name="cusType_sh" id="cusType_sh" style="width: 40px;">
      		<option value="">无</option>
      		<option value="A">A</option>
      		<option value="B">B</option>
      		<option value="C">C</option>
      		<option value="D">D</option>
      </select>
      <label>品牌名称：</label>  
      <input type="text" name="brandName_sh" id="brandName_sh" ></input>  
      <label>销售人员：</label>  
       <select id="userId_sh" name="userId_sh" style="width:50px;">
                	<option value="">无</option>
                	<%
                		List<GcmsUser> users = SecurityUtil.getAllUser();
                		for(GcmsUser user : users){
                			%>
                			<option value="<%=user.getID() %>"><%=user.getUserName() %></option>
                			<%
                		}
                	%>
                </select>  
      <a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="doSearch()">search</a>
</form>
</div>
<div id="dataArea" style="border: 1px solid #6593CF; font-size: 14px ;">
<%
	List<Customer> allCustomer = (List<Customer>)request.getAttribute("allCustomer");
	if(allCustomer==null||allCustomer.size() ==0){
%>
	<div style="border-bottom: 1px solid #6593CF;padding:5px; padding-bottom: 15px ;padding-left: 5px;">
		<p> No Data found here!</p>
	</div>
<%
	}
	for(Customer customer : allCustomer){
%>
<div style="border-bottom: 1px solid #6593CF;padding:5px; padding-bottom: 15px ;padding-left: 5px;">
	<div>公司名称：<%=customer.getCustomerName() %> &nbsp; | &nbsp; 客户分类：<%=customer.getCusType() %>
	&nbsp; | &nbsp; 销售人员：<%=GcmsUserService.instance.getUserByID(customer.getUserId()).getUserName() %>
	</div> 
	<a href="#" class="easyui-linkbutton"  onclick="viewCusDetail('<%=customer.getID() %>')">公司信息</a> 
    <a href="#" class="easyui-linkbutton"  onclick="listBrand('<%=customer.getID() %>')">所有品牌</a> 
    <a href="#" class="easyui-linkbutton"  onclick="listStore('<%=customer.getID() %>')">所有店铺</a> 
    <div id="detail_<%=customer.getID() %>">
    	
    </div>
</div>
<%
	}
%>     
</div>
<p>
	<a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="exportCusInfo()">导出公司信息</a>
	<a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="exportBrandInfo()">导出品牌信息</a>
	<a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="exportStoreInfo()">导出店铺信息</a>
</p>

<!-- customer start -->
<div id="loginInfoEdit_cus"  
    style="padding: 5px; width: 600px; height: 450px;">  
    <div class="ToolTip_Form" id="table_loginInfoEdit">  
       <input type="text" name="ID" id="ID" value="" style="display: none"/>
       <ul>    
            <li>  
                <label>客户分类：</label>  
                <input type="text" class="easyui-validatebox" name="cusType" id="cusType" required="true"></input>  
            </li>  
            <li>  
                <label>公司名称：</label>  
                <input type="text" class="easyui-validatebox" name="customerName" id="customerName" required="true"></input>  
            </li>  
            <li>  
                <label>公司地址：</label>  
                <input type="text" class="easyui-validatebox" name="visitedAddress" id="visitedAddress" required="true"></input>  
            </li> 
            <li>  
                <label>公司网站：</label>  
                <input type="text" class="easyui-validatebox" name="webSite" id="webSite"></input>  
            </li> 
            <li>  
                <label>公司联系人公司联系方式:</label>  
                <input type="hidden" name="contactInfo" id="contactInfo"/>
                <div id="contactInfoDiv">
                </div>
            </li> 
            <li>  
                <label>是否使用过客流统计：</label>  
                <input type="text" class="easyui-validatebox" name="everUsedFlowCover" id="everUsedFlowCover" required="true"></input>  
            </li> 
           <li>  
                <label>客流统计型号：</label>  
                <input type="text" class="easyui-validatebox" name="flowCoverType" id="flowCoverType" ></input>  
            </li> 
            <li>  
                <label>公司信息来源：</label>  
                <input type="text" class="easyui-validatebox" name="inforSource" id="inforSource" required="true"></input>  
            </li> 
           <li>  
                <label>销售人员：</label>  
                <select id="userId" name="userId"  required="true">
                	<option value=""></option>
                	<%
                		for(GcmsUser user : users){
                			%>
                			<option value="<%=user.getID() %>"><%=user.getUserName() %></option>
                			<%
                		}
                	%>
                </select>
            </li> 
        </ul>
    </div>  
</div>  
<!-- custoemr end -->

<!-- brand start -->
<!-- 编辑 -->  
<div id="loginInfoEdit_brand"  
    style="padding: 5px; width: 600px; height: 450px;">  
    <div class="ToolTip_Form" id="table_loginInfoEdit"">  
       <input type="hidden" name="ID" id="ID" value="" />
       <ul>    
            <li>  
                <label>品牌名称：</label>  
                <input type="text" class="easyui-validatebox" name="brandName_b" id="brandName_b" required="true"></input>  
            </li>
            <li>  
                <label>品牌类型：</label>  
                <input type="text" class="easyui-validatebox" name="clothType_b" id="clothType_b" ></input>  
            </li> 
            <li>  
                <label>品牌网站：</label>  
                <input type="text" class="easyui-validatebox" name="webSite_b" id="webSite_b" ></input>  
            </li>
            <li>  
                <label>品牌地址：</label>  
                <input type="text" class="easyui-validatebox" name="Address_b" id="Address_b"  required="true"></input>  
            </li> 
            <li>  
                <label>品牌联系人/品牌联系人</label>  
                <input type="hidden" name="contactInfo" id="contactInfo"/>
                <div id="contactInfoDiv_b">
                </div> 
            </li> 
            <li>  
                <label>店铺数量：</label>  
                <input type="text" class="easyui-validatebox" name="storeNum_b" id="storeNum_b" ></input>  
            </li> 
            <li>  
                <label>收银系统型号：</label>  
                <input type="text" class="easyui-validatebox" name="chargerType_b" id="chargerType_b" ></input>  
            </li> 
            <li>  
                <label>拜访记录：</label>  
                <input type="hidden" name="historyInfo" id="historyInfo"/>
                <div id="hisToryInfoDiv">
                </div> 
            </li> 
            <li>  
                <label>销售人员：</label>  
                <select id="userId_b" name="userId_b" required="true">
                	<option value="">无</option>
                	<%
                		for(GcmsUser user : users){
                			%>
                			<option value="<%=user.getID() %>"><%=user.getUserName() %></option>
                			<%
                		}
                	%>
                </select>
            </li> 
            <li>  
                <label>所属公司：</label>  
                <select id="customerId_b" name="customerId_b" required="true">
                	<option value="">无</option>
                	<%
                		List<Customer> customers = CustomerService.instance.getAllCustomer();
                		for(Customer cus : customers){
                			%>
                			<option value="<%=cus.getID() %>"><%=cus.getCustomerName() %></option>
                			<%
                		}
                	%>
                </select>
            </li> 
        </ul>  
    </div>  
</div> 
<!-- brand end -->


<!-- store start -->
<div id="loginInfoEdit_store"  
    style="padding: 5px; width: 600px; height: 450px;">  
    <div class="ToolTip_Form" id="table_loginInfoEdit" >  
       <input type="hidden"" name="ID" id="ID" value=""/>
       <ul>    
			<li>  
                <label>店铺地址：</label>  
                <input type="text" class="easyui-validatebox" name="storeAddress_s" id="storeAddress_s" maxlength_d="20" required_d="true"></input>  
            </li>  
            <li>  
                <label>店铺负责人：</label>  
                <input type="text" class="easyui-validatebox" name="storeManeger_s" id="storeManeger_s" maxlength_d="20" required_d="true"></input>  
            </li> 
            <li>  
                <label>店铺负责人联系电话：</label>  
                <input type="text" class="easyui-validatebox" name="phoneOfStoreManager_s" id="phoneOfStoreManager_s" maxlength_d="20" required_d="true"></input>  
            </li>  
            <li>  
                <label>销售人员：</label>  
                <select id="userId_s" name="userId_s" required="true">
                	<option value="">无</option>
                	<%
                		for(GcmsUser user : users){
                			%>
                			<option value="<%=user.getID() %>"><%=user.getUserName() %></option>
                			<%
                		}
                	%>
                </select>
            </li> 
             <li>  
                <label>所属公司：</label>  
                <select id="customerId_s" name="customerId_s" required="true">
                	<option value="">无</option>
                	<%
                		for(Customer cus : customers){
                			%>
                			<option value="<%=cus.getID() %>"><%=cus.getCustomerName() %></option>
                			<%
                		}
                	%>
                </select>
            </li> 
        </ul>  
    </div>  
</div>  
<!-- store end -->





</body>
</html>